const {
  req
} = require('../../utils/requests')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    parentData: {},
    id: '',
    htmltxt: '',
    commentsList: {}, //评论列表
    articlesList: [], //相关推荐
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let id = options.id
    let self = this
    // 获取id值
    this.setData({
      id: JSON.parse(options.id)
    })
    // 获取文本信息
    req('https://view.inews.qq.com/k/' + this.data.id + '?web_channel=wap&openApp=false').then(res => {
      let gtml = res.data
      let textstrs = gtml.replace(/<[^>]*>|/g, "")
      this.setData({
        htmltxt: textstrs
      })
    })
    // 评论信息
    req('https://view.inews.qq.com/getQQNewsComment?article_id=' + self.data.id + '&reqNum=5&devid=75637b7e46d6b77d&currentChannelId=news_news_share').then(res => {
      this.setData({
        commentsList: res.data
      })
    })
    // 相关推荐
    this.getRelatedModules()

  },
  getRelatedModules() {
    let self = this
    wx.request({
      url: 'https://view.inews.qq.com/web_feed/getRelatedModules',
      method: "POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        "cur_news_id": self.data.id,
        "device_id": "ukey_168208804841800312",
        "open_id": "ukey_168208804841800312",
        "base_req": {
          "from": "qq_web"
        },
        "relate_req": {
          "modules": [
            "1",
            "2"
          ]
        }
      },
      success(res) {
        let article_info = res.data.data.article_info
        self.setData({
          articlesList: article_info.articles
        })
      }
    })
  }



})